function getIcon() {
  const id = 'icon-' + this.id
  const svg = document.getElementById(id)
  if (svg) {
    const path = svg.getElementsByTagName('path')[0]
    if (path) {
      path.setAttribute('fill', this.color)

      let svgString =
        '<svg xmlns="http://www.w3.org/2000/svg" width="14px" height="14px">' +
        path.outerHTML +
        '</svg>'
      if (
        id === 'icon-historyBuild' ||
        id === 'icon-resourceBusinessBuild' ||
        id === 'icon-warning'
      ) {
        svgString =
          '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024" width="14px" height="14px">' +
          path.outerHTML +
          '</svg>'
      }
      return 'data:image/svg+xml,' + encodeURIComponent(svgString)
    }
  }
}

// 给tree增加icon属性
export function addIcon(tree) {
  tree.map((item) => {
    if (item.children) {
      addIcon(item.children)
    } else {
      if (item.color) {
        item.icon = getIcon.call(item)
      }
    }
  })
}

export const communityTree = [
  {
    id: 'community',
    name: '社区信息',
    checked: false,
    children: [
      {
        id: 'communityRegion',
        name: '社区边界',
        checked: false,
        color: '#5B9BD5',
      },
      {
        id: 'synthesizeStation',
        name: '社区综合服务站/党群服务中心',
        checked: false,
        color: '#FF0000',
      },
      {
        id: 'cultureRoom',
        name: '社区文化服务中心',
        checked: false,
        color: '#DF3621',
      },
      {
        id: 'safeStation',
        name: '社区卫生服务站',
        checked: false,
        color: '#D98D59',
      },
      {
        id: 'communityElder',
        name: '社区养老服务设施',
        checked: false,
        color: '#8EA9DB',
      },
      {
        id: 'communityDinner',
        name: '社区老年食堂',
        checked: false,
        color: '#FFC000',
      },
      {
        id: 'nursery',
        name: '婴幼儿照护服务设施/托儿所',
        checked: false,
        color: '#A9D08E',
      },
      {
        id: 'kindergarten',
        name: '幼儿园',
        checked: false,
        color: '#92D050',
      },
      {
        id: 'activitySpace',
        name: '公园绿地活动场地',
        checked: false,
        color: '#00B050',
      },
      {
        id: 'manageHouse',
        name: '物业管理用房',
        checked: false,
        color: '#2F75B5',
      },
      {
        id: 'embeddedService',
        name: '社区嵌入式服务综合体',
        checked: false,
        color: '#48A088',
      },
      {
        id: 'updateRoad',
        name: '步行道',
        checked: false,
        color: '#00B0F0',
      },
    ],
  },
]

addIcon(communityTree)

export const residenceTree = [
  {
    id: 'residenceRegion',
    name: '小区信息',
    checked: false,
    children: [
      {
        id: 'residence',
        name: '小区边界',
        checked: false,
        color: '#006fff',
      },
      {
        id: 'oldBuilding',
        name: '隐患楼栋',
        checked: false,
        color: '#ff0000',
      },
      {
        id: 'warning',
        name: '隐患点位',
        checked: false,
        color: '#F77656',
      },
      {
        id: 'buildingAge',
        name: '建筑年代',
        checked: false,
        color: '#ff0000',
      },
    ],
  },
]

addIcon(residenceTree)

export const streetTree = [
  {
    id: 'street',
    name: '街道信息',
    checked: false,
    children: [
      {
        id: 'updateStreet',
        name: '老旧街区',
        checked: false,
        color: '#833C0C',
      },
      {
        id: 'updateFactory',
        name: '老旧厂区',
        checked: false,
        color: '#333F4F',
      },
      {
        id: 'updateBusiness',
        name: '老旧商业区',
        checked: false,
        color: '#BF8F00',
      },
      {
        id: 'updateShop',
        name: '老旧商贸市场',
        checked: false,
        color: '#8D8FB6',
      },
      {
        id: 'updateArea',
        name: '闲置用地面积',
        checked: false,
        color: '#548235',
      },
      {
        id: 'resourceBusinessBuild',
        name: '老旧商务楼宇',
        checked: false,
        color: '#7030A0',
      },
      {
        id: 'historyBuild',
        name: '历史建筑、传统风貌建筑',
        checked: false,
        color: '#806000',
      },
      {
        id: 'parkingProblemRoad',
        name: '存在乱停乱放车辆的道路',
        checked: false,
        color: '#ff6e3b',
      },
    ],
  },
]

addIcon(streetTree)

export const regionTree = [
  {
    id: 'region',
    name: '专项数据',
    checked: false,
    children: [
      {
        id: 'liveRange',
        name: '居住区',
        checked: false,
        color: '#34EB38',
      },
      {
        id: 'historyCultureRange',
        name: '历史文化片区',
        checked: false,
        color: '#FCCA00',
      },
      {
        id: 'historyBuildRange',
        name: '历史建筑',
        checked: false,
        color: '#E99D42',
      },
      {
        id: 'vacantRange',
        name: '闲置空置用地',
        checked: false,
        color: '#30C0B4',
      },
      {
        id: 'businessRange',
        name: '旧商业商务用地',
        checked: false,
        color: '#D7BDF9',
      },
      {
        id: 'industryRange',
        name: '老旧商业仓储区',
        checked: false,
        color: '#5D59A7',
      },
      {
        id: 'shopRange',
        name: '老旧商贸市场',
        checked: false,
        color: '#7F83F7',
      },
      {
        id: 'otherRange',
        name: '其他需要更新的片区',
        checked: false,
        color: '#FFFF00',
      },
      {
        id: 'IdleRange',
        name: '闲置空间',
        checked: false,
        color: '#81B337',
      },
      {
        id: 'liveManageRange',
        name: '可经营空间',
        checked: false,
        color: '#FFBF6B',
      },
      {
        id: 'businessStreetRange',
        name: '街道空间',
        checked: false,
        color: '#2F75B5',
      },
      {
        id: 'businessGreenRange',
        name: '公园绿地',
        checked: false,
        color: '#10B55B',
      },
      {
        id: 'businessUpdateRange',
        name: '需要更新提升的楼宇',
        checked: false,
        color: '#E99D42',
      },
      {
        id: 'communityLiveVacant',
        name: '社区闲置空间',
        checked: false,
        color: '#81B337',
      },
      {
        id: 'communityLiveManage',
        name: '社区可经营空间',
        checked: false,
        color: '#FFBF6B',
      },
    ],
  },
]

addIcon(regionTree)
